package com.rem.concurrency.juc.my5Add;

import java.util.concurrent.CountDownLatch;

/**
 * 做减法
 * 允许一个或多个线程等待直到在其他线程中执行的一组操作完成的同步辅助。
 *
 * @author Rem
 * @date 2021-03-09
 */

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        //线程计数器
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " go");

                //计数减一
                countDownLatch.countDown();
            }).start();
        }

        //等待 知道计数器减到0为止 才进行后面的操作
        countDownLatch.await();

        System.out.println("is close");
    }

}
